package cn.yitun.chat.yitunserverimapicore.business.voice.action;

import cn.yitun.chat.yituncommonmessage.ExceptionEnum;
import cn.yitun.chat.yituncommonmessage.YitunException;
import cn.yitun.chat.yituncommonmessage.impl.HeadImpl;
import cn.yitun.chat.yituncommonmessage.result.ResultMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitungeneral.annotation.action.ActionMapping;
import cn.yitun.chat.yitungeneral.annotation.parameter.JsonDefine;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.dto.remote.VoicePushDto;
import cn.yitun.chat.yitunservercommonlib.util.NumUtil;
import org.springframework.stereotype.Component;

/**
 * 
 * @author yitun
 *
 */
@Component
@ActionMapping(value = ActionTypeConstant.VOICE_ACTION_PUSH)
public class VoiceAction {



	@ActionMapping(value = "1.1.0001")
	public ResultMessage getVoiceServerPort() {
		ResultMessage message = new ResultMessage();
		message.bodyPut("voiceAddress", null);
		return message;
	}

	@ActionMapping(value = "1.1.0002")
	public ResultMessage getUserVoiceAddress() {
		ResultMessage message = new ResultMessage();
		message.bodyPut("voiceAddress", null);
		return message;
	}

	@ActionMapping(value = "1.1.0003")
	public ResultMessage voiceRequest(HeadImpl head, @JsonDefine("data") VoicePushDto query) {
		if (NumUtil.isInValid(query.getReceiveUserId()) || NumUtil.isInValid(query.getSendUserId()))
			throw new YitunException(ExceptionEnum.LOSE_FILED);

		ResultMessage message = new ResultMessage();
		message.bodyPut("receiveUserId", query.getReceiveUserId());
		message.bodyPut("sendUserId", query.getSendUserId());
		
		message.setHead(head);
		return message;
	}

	@ActionMapping(value = "1.1.0004")
	public ResultMessage voiceResponse(HeadImpl head, @JsonDefine("data") VoicePushDto query) {

		if (NumUtil.isInValid(query.getReceiveUserId()) || NumUtil.isInValid(query.getSendUserId())
				|| YitunStringUtil.isEmpty(query.getActionType()))
			throw new YitunException(ExceptionEnum.LOSE_FILED);

		ResultMessage message = new ResultMessage();
		message.bodyPut("receiveUserId", query.getReceiveUserId());
		message.bodyPut("sendUserId", query.getSendUserId());
		message.bodyPut("actionType", query.getActionType());
		
		message.setHead(head);
		return message;
	}
}
